﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.yy.ui.controls {
    import flash.events.*;
    import flash.display.*;
    import com.fminutes.vinciUI.events.*;
    import com.fminutes.vinciUI.core.*;

    public class Dialog extends UIComponent {

        public static const LAYOUT_LEFT:String = "left";
        public static const LAYOUT_RIGHT:String = "right";
        public static const LAYOUT_CENTER:String = "center";
        public static const LAYOUT_CUSTOM:String = "custom";

        private var _tipContainer:DisplayObject;
        private var _buttonLayout:String;
        private var confirmBtn:DisplayObject;
        private var cancelBtn:DisplayObject;
        private var closeBtn:DisplayObject;
        public var edgeDistance:Number = 15;
        private var _buttonDistance:Number;

        public function Dialog(_arg1:DisplayObject, _arg2:DisplayObject=null, _arg3:DisplayObject=null, _arg4:DisplayObject=null, _arg5:DisplayObject=null, _arg6:String="right", _arg7:Number=20){
            this._tipContainer = _arg2;
            this.confirmBtn = _arg3;
            this.cancelBtn = _arg4;
            this.closeBtn = _arg5;
            this._buttonLayout = _arg6;
            background = _arg1;
            this._buttonDistance = _arg7;
            this.init();
        }
        private function init():void{
            if (this._tipContainer != null){
                addChild(this._tipContainer);
            };
            if (this.confirmBtn != null){
                addChild(this.confirmBtn);
                this.confirmBtn.addEventListener(MouseEvent.CLICK, this.dialogConfirm);
            };
            if (this.cancelBtn != null){
                addChild(this.cancelBtn);
                this.cancelBtn.addEventListener(MouseEvent.CLICK, this.dialogCancel);
            };
            if (this.closeBtn != null){
                addChild(this.closeBtn);
                this.closeBtn.addEventListener(MouseEvent.CLICK, this.dialogClose);
            };
            this.updateUI();
        }
        private function dialogConfirm(_arg1:MouseEvent):void{
            var _local2:UIEvent = new UIEvent(UIEvent.DIALOG_OK);
            dispatchEvent(_local2);
        }
        private function dialogCancel(_arg1:MouseEvent):void{
            var _local2:UIEvent = new UIEvent(UIEvent.DIALOG_CANCEL);
            dispatchEvent(_local2);
        }
        private function dialogClose(_arg1:MouseEvent):void{
            var _local2:UIEvent = new UIEvent(UIEvent.DIALOG_CLOSE);
            dispatchEvent(_local2);
        }
        public function get tipContainer():DisplayObject{
            return (this._tipContainer);
        }
        public function set tipContainer(_arg1:DisplayObject):void{
            if (((_arg1) && (!((_arg1 == this._tipContainer))))){
                removeChild(this._tipContainer);
                this._tipContainer = _arg1;
                addChildAt(this._tipContainer, 1);
            };
            this.updateUI();
        }
        public function get buttonLayout():String{
            return (this._buttonLayout);
        }
        public function set buttonLayout(_arg1:String):void{
            this._buttonLayout = _arg1;
        }
        override public function updateUI():void{
            super.updateUI();
            if (this.closeBtn != null){
                this.closeBtn.x = (((background.x + background.width) - this.closeBtn.width) - 10);
                this.closeBtn.y = (background.y + 10);
            };
            switch (this._buttonLayout){
                case Dialog.LAYOUT_RIGHT:
                    if (this.cancelBtn != null){
                        this.cancelBtn.x = (((background.x + background.width) - this.cancelBtn.width) - this.edgeDistance);
                        this.cancelBtn.y = (((background.y + background.height) - this.cancelBtn.height) - this.edgeDistance);
                    };
                    if (this.confirmBtn != null){
                        if (this.cancelBtn != null){
                            this.confirmBtn.x = ((this.cancelBtn.x - this.confirmBtn.width) - this._buttonDistance);
                            this.confirmBtn.y = this.cancelBtn.y;
                        } else {
                            this.confirmBtn.x = (((background.x + background.width) - this.confirmBtn.width) - this.edgeDistance);
                            this.confirmBtn.y = (((background.y + background.height) - this.confirmBtn.height) - this.edgeDistance);
                        };
                    };
                    break;
                case Dialog.LAYOUT_LEFT:
                    if (this.confirmBtn != null){
                        this.confirmBtn.x = (background.x + this.edgeDistance);
                        this.confirmBtn.y = (((background.y + background.height) - this.confirmBtn.height) - this.edgeDistance);
                    };
                    if (this.cancelBtn != null){
                        if (this.confirmBtn != null){
                            this.cancelBtn.x = ((this.confirmBtn.x + this.confirmBtn.width) + this._buttonDistance);
                            this.cancelBtn.y = this.confirmBtn.y;
                        } else {
                            this.cancelBtn.x = (background.x + this.edgeDistance);
                            this.cancelBtn.y = (((background.y + background.height) - this.cancelBtn.height) - this.edgeDistance);
                        };
                    };
                    break;
                case Dialog.LAYOUT_CENTER:
                    if (((!((this.confirmBtn == null))) && (!((this.cancelBtn == null))))){
                        this.confirmBtn.x = (((background.x + (background.width / 2)) - (this._buttonDistance / 2)) - this.confirmBtn.width);
                        this.confirmBtn.y = (((background.y + background.height) - this.edgeDistance) - this.confirmBtn.height);
                        this.cancelBtn.x = ((this.confirmBtn.x + this.confirmBtn.width) + this._buttonDistance);
                        this.cancelBtn.y = this.confirmBtn.y;
                    };
                    if ((((this.confirmBtn == null)) && (!((this.cancelBtn == null))))){
                        this.cancelBtn.x = ((background.x + (background.width / 2)) - (this.cancelBtn.width / 2));
                        this.cancelBtn.y = (((background.y + background.height) - this.cancelBtn.height) - this.edgeDistance);
                    };
                    if (((!((this.confirmBtn == null))) && ((this.cancelBtn == null)))){
                        this.confirmBtn.x = ((background.x + (background.width / 2)) - (this.confirmBtn.width / 2));
                        this.confirmBtn.y = (((background.y + background.height) - this.confirmBtn.height) - this.edgeDistance);
                    };
                    break;
                case Dialog.LAYOUT_CUSTOM:
                    break;
            };
        }
        public function get buttonDistance():Number{
            return (this._buttonDistance);
        }
        public function set buttonDistance(_arg1:Number):void{
            this._buttonDistance = _arg1;
            this.updateUI();
        }
        public function dispose():void{
            removeAllChildren();
            this._tipContainer = null;
            this.cancelBtn = null;
            this.confirmBtn = null;
        }

    }
}//package com.fminutes.vinciUI.controls 
